﻿Public Class 修改

    Private Sub 修改_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        For Each sp As String In My.Computer.Ports.SerialPortNames
            ComboBox1.Items.Add(sp)
        Next
        If ComboBox1.Items.Count > 0 Then
            ComboBox1.SelectedIndex = 0
        End If
        Try
            Dim XDoc As New Xml.XmlDocument
            XDoc.Load(".\data\init.xml")
            Dim XReader As New Xml.XmlNodeReader(XDoc)
            Dim ParaName As String = ""
            While XReader.Read
                Select Case XReader.NodeType
                    Case Xml.XmlNodeType.Element
                        ParaName = XReader.Name
                    Case Xml.XmlNodeType.Text
                        Select Case ParaName
                            Case "port" : Me.ComboBox1.Text = XReader.Value
                            Case "l_hour" : Me.TextBox1.Text = XReader.Value
                            Case "l_min" : Me.TextBox2.Text = XReader.Value
                            Case "pname" : pname = XReader.Value
                        End Select
                End Select
            End While
        Catch ex As Exception
            System.IO.File.Create(".\data\init.xml").Dispose()
            主页.ts(ex.ToString)
        End Try
    End Sub

    Private Sub 修改_Closed(sender As Object, e As EventArgs) Handles Me.Closed
        Dim XWriter As New Xml.XmlTextWriter(".\data\init.xml", System.Text.Encoding.GetEncoding("UTF-8")) With {
            .Formatting = Xml.Formatting.Indented
        }
        XWriter.WriteRaw("<?xml version=""1.0"" encoding=""utf-8"" ?>")
        XWriter.WriteStartElement("Settings")
        XWriter.WriteElementString("port", Me.ComboBox1.Text)
        XWriter.WriteElementString("l_hour", Me.TextBox1.Text)
        XWriter.WriteElementString("L_min", Me.TextBox2.Text)
        XWriter.WriteElementString("pname", Me.TextBox3.Text)
        XWriter.WriteEndElement()
        XWriter.Close()
        主页.Neww()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim cmd As String
        cmd = "cmd /k explorer /select," + Application.StartupPath
        Call Shell(cmd)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Try
            System.Diagnostics.Process.Start(".\data\manage\SYDemo.exe")
        Catch ex As Exception
            主页.ts(ex.ToString)
        End Try
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        主页.Dj(InputBox("请输入学号"), False)
    End Sub
End Class